#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//以普通函数的方式定义筛选规则
bool mycomp(int i)
{
    return (i % 2 == 0);
}
//以函数对象的形式定义筛选规则
class mycomp2
{
public:
    bool operator()(const int &i)
    {
        return (i % 2 == 0);
    }
};

int main()
{   
    //partition()
    vector<int> myvector{1, 2, 3, 4, 5, 6, 7, 8, 9};
    vector<int>::iterator bound;
    bound = partition(myvector.begin(), myvector.end(), mycomp2());
    for (auto it = myvector.begin(); it != myvector.end(); it++)
    {
        cout << *it << " ";
    }
    cout << endl << "bound = " << *bound << endl;
    //stable_partition()
    vector<int> myvector1{1, 2, 3, 4, 5, 6, 7, 8, 9};
    vector<int>::iterator bound1;
    bound1 = stable_partition(myvector1.begin(), myvector1.end(), mycomp2());
    for (auto it = myvector1.begin(); it != myvector1.end(); it++)
    {
        cout << *it << " ";
    }
    cout << endl << "bound = " << *bound1;
    return 0;
}
